package com.xinchen.ssh.demo.utils;

import java.io.Serializable;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.lang.SerializationUtils;

/**
 * Description：
 *
 * @author Xin Chen
 * @version 1.0
 * @date 2016/12/15 11:08
 * @see 2016/12/15 11:08 Created
 ****************************************/
public final class ObjectUtils {
    private ObjectUtils() {
    }

    public static String toXml(Object o) {
        JSON jsonObject = JSONSerializer.toJSON(o);
        XMLSerializer xmlSerializer = new XMLSerializer();
        return xmlSerializer.write(jsonObject);
    }

    public static String toJSON(Object o) {
        JSON jsonObject = JSONSerializer.toJSON(o);
        return jsonObject.toString();
    }

    public static Object serializaClone(Serializable o) {
        return SerializationUtils.clone(o);
    }
}
